package com.nit.bike.mapper.basic;

import com.nit.bike.dto.basic.StationDTO;
import com.nit.bike.entity.basic.StationEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface StationMapper {
    int deleteByPrimaryKey(Long stationId);

    int insert(StationEntity record);

    int insertSelective(StationEntity record);

    StationEntity selectByPrimaryKey(Long stationId);

    int updateByPrimaryKeySelective(StationEntity record);

    int updateByPrimaryKey(StationEntity record);

    /**
     * 获取表格数据，查询条件自行编写对应代码，需区分模糊和相等，排序条件无需改动
     */
    @Select({"<script>SELECT *, station_id AS `key` " +
            "FROM basic_station " +
            "WHERE TRUE " +
            "<if test='stationName != null'> AND station_name LIKE CONCAT('%', #{stationName}, '%') </if>" +
            "ORDER BY " +
            "<if test='sortField != null'> ${sortField} ${sortOrder}, </if>" +
            "station_id desc " +
            "LIMIT #{start}, #{length}" +
            "</script>"})
    List<StationDTO> list4Table(
            @Param("start") Integer start,
            @Param("length") Integer length,
            @Param("stationName") String stationName,
            @Param("sortField") String sorterField,
            @Param("sortOrder") String sorterOrder) throws Exception;

    /**
     * 获取表格数据记录的总条数
     *
     * @Author: SN
     * @Date: 2019/01/30 18:15
     */
    @Select({"<script>SELECT COUNT(*) " +
            "FROM basic_station " +
            "WHERE TRUE " +
            "<if test='stationName != null'> AND station_name LIKE CONCAT('%', #{stationName}, '%') </if>" +
            "</script>"})
    Long count4Table(
            @Param("stationName") String stationName) throws Exception;


    /**
     * 查询站点list
     *
     * @Author: zxq
     * @Date: 2020/8/20
     */
    @Select("SELECT station_id, station_name " +
            "FROM basic_station " +
            "WHERE TRUE")
    @Results({
            @Result(column = "station_id", property = "stationId"),
            @Result(column = "station_name", property = "stationName")
    })
    List<StationDTO> listStation() throws Exception;
}
